// TaskMapper.java
package com.scuec.groupfive.mapper;

import com.scuec.groupfive.entity.DailyTask;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TaskMapper {
    @Select("SELECT * FROM daily_tasks WHERE user_id = #{userId} AND DATE(task_date) = CURRENT_DATE()")
    List<DailyTask> selectTodayTasks(@Param("userId") Long userId);

    @Insert("INSERT INTO daily_tasks (plan_id, user_id, task_date, status, content) " +
            "VALUES (#{planId}, #{userId}, #{taskDate}, #{status}, #{content})")
    int insertTask(DailyTask task);

    @Update("UPDATE daily_tasks SET content = #{content}, status = #{status}, updated_at = NOW() " +
            "WHERE task_id = #{taskId} AND user_id = #{userId}")
    int updateTask(DailyTask task);

    @Update("UPDATE daily_tasks SET status = #{status}, updated_at = NOW() " +
            "WHERE task_id = #{taskId} AND user_id = #{userId}")
    int updateTaskStatus(@Param("taskId") Long taskId,
                         @Param("userId") Long userId,
                         @Param("status") String status);

    @Delete("DELETE FROM daily_tasks WHERE task_id = #{taskId} AND user_id = #{userId}")
    int deleteTask(@Param("taskId") Long taskId,
                   @Param("userId") Long userId);

    @Select("SELECT COUNT(*) FROM daily_tasks WHERE user_id = #{userId} AND DATE(task_date) = CURRENT_DATE()")
    int countTodayTasks(@Param("userId") Long userId);

    @Select("SELECT COUNT(*) FROM daily_tasks WHERE user_id = #{userId} AND DATE(task_date) = CURRENT_DATE() AND status = 'completed'")
    int countCompletedTodayTasks(@Param("userId") Long userId);
}